<template>
    <div
        class="editstudent"
        v-loading="loading3"
        element-loading-text="数据加载中。。。。"
        element-loading-spinner="el-icon-loading"
    >
        <div class="addstu-box">
            <div class="title">
                <h1>基本信息</h1>
            </div>
            <div class="addstu-box-contain">
                <el-form
                    ref="studentInfoDetail"
                    :rules="fieldRules"
                    :inline="true"
                    :model="info.studentInfoDetail.studentInfo"
                    class="demo-form-inline"
                >
                    <el-row>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>学生姓名：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-input
                                        v-model="info.studentInfoDetail.studentInfo.name"
                                        placeholder="学生姓名"
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>学校名称：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-input
                                        v-model="info.studentInfoDetail.studentInfo.school"
                                        placeholder="学校名称"
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>学籍号：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-input
                                        :disabled="true"
                                        v-model="info.studentInfoDetail.studentInfo.oemAccount"
                                        placeholder="学籍号"
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>学生学制：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-select
                                        v-model="info.studentInfoDetail.studentInfo.schoolSystem"
                                        placeholder="请选择"
                                        :change="student_system_cache_change"
                                    >
                                        <el-option
                                            v-for="item in student_system_cache_options"
                                            :key="item.fId"
                                            :label="item.fSystemName"
                                            :value="item.fId"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>就读年级：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-select
                                        v-model="info.studentInfoDetail.studentInfo.grade"
                                        placeholder="请选择"
                                        :change="student_grade_cache_change"
                                    >
                                        <el-option
                                            v-for="item in grade_cache_gradeOptions"
                                            :key="item.value"
                                            :label="item.fGradeName"
                                            :value="item.fId"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="7">
                                <i>学生账号：</i>
                            </el-col>
                            <el-col :span="15">
                                <el-input
                                    v-model="info.studentInfoDetail.studentInfo.account"
                                    placeholder="学生账号"
                                ></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>家长姓名：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-input
                                        v-model="info.studentInfoDetail.studentInfo.parentName"
                                        placeholder="家长姓名"
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="7">
                                <i>
                                    <em style="color:red">*</em> 联系电话：
                                </i>
                            </el-col>
                            <el-col :span="15">
                                <el-form-item label prop="phone" style="width:100%;">
                                    <el-input
                                        type="number"
                                        :disabled="true"
                                        v-model="info.studentInfoDetail.studentInfo.phone"
                                        placeholder="联系电话"
                                    ></el-input>
                                    <!-- {{info.studentInfoDetail.studentInfo.phoneStr}} -->
                                </el-form-item>
                            </el-col>
                        </el-col>
                        <!-- <el-col :span="8">
                          <el-col :span="7">
                              <i>备用电话：</i>
                          </el-col>
                          <el-col :span="15">
                            <el-form-item label prop="phone" style="width:100%;">
                              <el-input type="number" :disabled="true" v-model="info.studentInfoDetail.studentInfo.sparePhone" placeholder="备用电话"></el-input>
                            </el-form-item>
                          </el-col>
                        </el-col>-->
                        <el-col :span="8" v-if="!this.customerSource">
                            <el-col :span="7">
                                <i>
                                    <em style="color:red">*</em> 客户来源：
                                </i>
                            </el-col>
                            <el-col :span="15">
                                <el-form-item label prop="dataFrom" style="width:100%;">
                                    <el-select
                                        :disabled="true"
                                        v-model="info.studentInfoDetail.studentInfo.dataFrom"
                                        placeholder="请选择"
                                        :change="student_data_from_change"
                                    >
                                        <el-option
                                            v-for="item in student_data_from_options"
                                            :key="item.key"
                                            :label="item.value"
                                            :value="item.key"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row>
                        <!-- <el-col :span="8" v-if="!this.customerSource">
                          <el-col :span="7">
                            <i> <em style="color:red">*</em> 客户来源：</i>
                          </el-col>
                          <el-col :span="15">
                            <el-form-item label prop="dataFrom" style="width:100%;">
                              <el-select :disabled="true" 
                              v-model="info.studentInfoDetail.studentInfo.dataFrom"
                              placeholder="请选择"
                              :change="student_data_from_change"
                            >
                              <el-option
                                v-for="item in student_data_from_options"
                                :key="item.key"
                                :label="item.value"
                                :value="item.key"
                                
                              ></el-option>
                            </el-select>
                            </el-form-item>
                            
                          </el-col> 
                        </el-col>-->
                        <el-col :span="8" v-if="!this.customerImportDepartment">
                            <el-col :span="7">
                                <i>导入部门：</i>
                            </el-col>
                            <el-col :span="15">
                                <el-form-item>
                                    <el-select
                                        :disabled="true"
                                        clearable
                                        v-model="info.studentInfoDetail.studentInfo.importDepartment"
                                        placeholder="请选择"
                                    >
                                        <el-option
                                            v-for="item in student_import_department"
                                            :key="item.key"
                                            :label="item.value"
                                            :value="item.key"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="2">
                            <i>所在地区：</i>
                        </el-col>
                        <el-col :span="10" style="text-algin:left; margin-left: 16px !important">
                            <el-cascader
                                size="large"
                                :options="options"
                                v-model="selectedOptions"
                                @change="handleChange"
                            ></el-cascader>
                        </el-col>
                        <el-col :span="8">
                            <el-input
                                v-model="info.studentInfoDetail.studentInfo.areaInput"
                                placeholder="请输入详细地址"
                            ></el-input>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="addstu-box">
            <div class="title">
                <h1>客户信息</h1>
            </div>
            <div class="addstu-box-contain">
                <el-form
                    :inline="true"
                    :model="info.studentInfoDetail.studentInfo"
                    class="demo-form-inline"
                >
                    <el-row>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>客户类型：</i>
                                </el-col>
                                <el-col :span="14 ">
                                    <el-select
                                        :disabled="true"
                                        v-model="info.studentInfoDetail.studentInfo.type"
                                        placeholder="请选择"
                                        @change="typeChange"
                                    >
                                        <el-option
                                            v-for="item in student_type_options"
                                            :key="item.value"
                                            :label="item.value"
                                            :value="item.key"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="6" @change="student_progress_change">
                                    <i>客户进展：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-select
                                        :disabled="true"
                                        v-model="info.studentInfoDetail.studentInfo.progress"
                                        placeholder="请选择"
                                        @change="progressChange"
                                    >
                                        <el-option
                                            v-for="item in student_progress_options"
                                            :key="item.value"
                                            :label="item.value"
                                            :value="item.key"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="8">
                                    <i>获取方式</i>
                                </el-col>
                                <el-col :span="14">
                                    <el-select
                                        :disabled="true"
                                        v-model="info.studentInfoDetail.studentInfo.dataFromType"
                                        placeholder="请选择"
                                    >
                                        <el-option
                                            v-for="item in student_data_from_type_options"
                                            :key="item.value"
                                            :label="item.value"
                                            :value="item.key"
                                        >{{item.value}}</el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-col :span="7">
                                <i>学生性别：</i>
                            </el-col>
                            <el-col :span="14">
                                <el-radio-group
                                    v-model="info.studentInfoDetail.studentInfo.sex"
                                    style="margin-top:6%"
                                >
                                    <el-radio label="1">男</el-radio>
                                    <el-radio label="2">女</el-radio>
                                </el-radio-group>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="6">
                                    <i>学生年龄：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-input
                                        max="100"
                                        min="1"
                                        type="number"
                                        v-model="info.studentInfoDetail.studentInfo.age"
                                        placeholder
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="8">
                                    <i>身份证号码：</i>
                                </el-col>
                                <el-col :span="14">
                                    <el-input
                                        v-model="info.studentInfoDetail.studentInfo.idCard"
                                        placeholder
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="6">
                                    <i>微信：</i>
                                </el-col>
                                <el-col :span="14" style="margin-left:16px !important">
                                    <el-input
                                        v-model="info.studentInfoDetail.studentInfo.wechat"
                                        placeholder
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="6">
                                    <i>QQ：</i>
                                </el-col>
                                <el-col :span="15">
                                    <el-input
                                        type="number"
                                        v-model="info.studentInfoDetail.studentInfo.qq"
                                        placeholder
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="8">
                                    <i>邮箱：</i>
                                </el-col>
                                <el-col :span="14">
                                    <el-input
                                        type="email"
                                        v-model="info.studentInfoDetail.studentInfo.email"
                                        placeholder
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-row>
                                <el-col :span="7">
                                    <i>与家长关系：</i>
                                </el-col>
                                <el-col :span="14">
                                    <el-input
                                        v-model="info.studentInfoDetail.studentInfo.relationShip"
                                    ></el-input>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="薄弱学科：">
                                <el-checkbox-group
                                    v-model="student_weak_subject_select"
                                    @change="student_weak_subject_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_weak_subject"
                                        :label="item.key"
                                        :key="item.value"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row style="margin:0">
                        <el-col :span="24">
                            <span>
                                <i style="font-size:15px;font-weight: 500;">偏好教学风格：</i>
                            </span>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="专业能力：">
                                <el-checkbox-group
                                    v-model="student_like_profession_ability_select"
                                    @change="student_like_profession_ability_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_like_profession_ability"
                                        :label="item.key"
                                        :key="item.value"
                                        name="type"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="授课方式：">
                                <el-checkbox-group
                                    v-model="student_like_lecture_style_select"
                                    @change="student_like_lecture_style_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_like_lecture_style"
                                        :label="item.key"
                                        :key="item.value"
                                        name="type"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="语言表达：">
                                <el-checkbox-group
                                    v-model="student_like_expression_select2"
                                    @change="student_like_expression_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_like_expression"
                                        :label="item.key"
                                        :key="item.value"
                                        name="type"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="讲义板书：">
                                <el-checkbox-group
                                    v-model="student_like_blackboard_select"
                                    @change="student_like_blackboard_writing_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_like_blackboard_writing"
                                        :label="item.key"
                                        :key="item.value"
                                        name="type"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="家长类型：">
                                <el-checkbox-group
                                    v-model="student_parent_type_select"
                                    @change="student_parent_type_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_parent_type"
                                        :label="item.key"
                                        :key="item.value"
                                        name="type"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="addstu-box">
            <div class="title">
                <h1>签约信息</h1>
            </div>
            <div class="addstu-box-contain">
                <el-form :inline="true" class="demo-form-inline">
                    <el-row class="sign-box">
                        <el-table :data="listStudentSignInfo" ref="table">
                            <el-table-column prop="orderId" label="订单号"></el-table-column>
                            <el-table-column prop="product2" label="成单产品"></el-table-column>
                            <el-table-column prop="money" label="成单金额"></el-table-column>
                            <el-table-column prop="classNum" label="课时数"></el-table-column>
                            <el-table-column prop="signDate" label="签约时间"></el-table-column>
                            <el-table-column label="退单">
                                <template slot-scope="scope">
                                    <!-- {{scope.row.tuidandis}} -->
                                    <el-checkbox
                                        :disabled="scope.row.tuidandis"
                                        v-model="scope.row.isReturn"
                                        true-label="1"
                                        false-label="2"
                                        name="type"
                                        @change="tuidanChange(scope.$index,scope.row)"
                                    ></el-checkbox>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination
                            background
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="currentPage"
                            :page-sizes="[10, 50, 100, 200]"
                            :page-size="pageSize"
                            :total="total"
                        ></el-pagination>
                    </el-row>
                    <el-row></el-row>
                    <el-row>
                        <el-col>
                            <el-button @click="add">添加</el-button>
                            <el-table :data="studentSignInfo2">
                                <el-table-column prop="studentSignInfo2.orderId" label="订单号">
                                    <template slot-scope="scope">
                                        <el-input v-model="studentSignInfo2[scope.$index].orderId"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="studentSignInfo2.product" label="成单产品">
                                    <template slot-scope="scope">
                                        <el-select
                                            v-model="studentSignInfo2[scope.$index].product"
                                            placeholder="请选择"
                                        >
                                            <el-option
                                                v-for="item in student_order_product_options2"
                                                :key="item.value"
                                                :label="item.value"
                                                :value="item.key"
                                            ></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="studentSignInfo2.money" label="成单金额">
                                    <template slot-scope="scope">
                                        <el-input v-model="studentSignInfo2[scope.$index].money"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="studentSignInfo2.classNum" label="课时数">
                                    <template slot-scope="scope">
                                        <el-input v-model="studentSignInfo2[scope.$index].classNum"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="studentSignInfo2.signDate"
                                    label="签约时间"
                                    width="240"
                                >
                                    <template slot-scope="scope">
                                        <el-date-picker
                                            v-model="studentSignInfo2[scope.$index].signDate"
                                            type="datetime"
                                            placeholder="选择日期"
                                            value-format="yyyy-MM-dd HH:mm:ss"
                                            format="yyyy-MM-dd HH:mm:ss"
                                        ></el-date-picker>
                                        <!-- <el-button  @click="addSign()">确定</el-button> -->
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="studentSignInfo2.signDate"
                                    align="center"
                                    label="操作"
                                >
                                    <template slot-scope="scope">
                                        <el-button @click="addSign()">确定</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="成单对策：">
                                <el-checkbox-group
                                    v-model="student_sign_strategy_select"
                                    @change="student_sign_strategy_change"
                                >
                                    <el-checkbox
                                        v-for="item in student_sign_strategy"
                                        :label="item.key"
                                        :key="item.key"
                                        name="type"
                                        :value="item.value"
                                    >{{item.value}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-col :span="3">
                                <i>备注：</i>
                            </el-col>
                            <el-col :span="21">
                                <el-input
                                    style="margin-left:-5%"
                                    v-model="info.studentInfoDetail.studentInfoAttr.comment"
                                    type="textarea"
                                ></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <KtButton
            :label="$t('action.close')"
            perms="true"
            size="medium"
            style="margin-right: 2%;"
            @click="closeSelectedTag"
        ></KtButton>
        <kt-button
            class="stu-btn"
            :label="$t('action.save')"
            perms="true"
            size="medium"
            @click="handleSave()"
            :loading="editLoading"
        />
    </div>
</template>
<script>
import { hasPermission } from "@/permission/index.js";
import axios from "axios";
import KtButton from "@/views/Core/KtButton";
import api from "@/http/api";
import CrmTable from "@/views/Core/CrmTable";
import { regionData } from "element-china-area-data";
export default {
    name: "EditStudent",
    components: {
        KtButton,
        CrmTable
    },
    data() {
        return {
            disabled: false,
            selectDisabled: false,
            loading: false,
            customerSource: false,
            customerImportDepartment: false,
            loading3: false,
            info: {
                studentInfoDetail: {
                    studentInfo: {
                        dataFrom2: "",
                        account: "",
                        age: 0,
                        area: "",
                        areaInput: "",
                        assignDate: "",
                        assignType: "",
                        belongTo: "",
                        belongToType: "",
                        callDate: "",
                        callNum: 0,
                        city: "",
                        code: "",
                        createDate: "",
                        createPeople: "",
                        createType: "",
                        dataFrom: "",
                        dataFromInterface: "",
                        dataFromType: "",
                        email: "",
                        grade: "",
                        id: "",
                        idCard: "",
                        importDepartment: "",
                        isLock: "",
                        isSign: "",
                        moveDate: "",
                        name: "",
                        nextTrackingDate: "",
                        oemAccount: "",
                        oemType: "",
                        oneLevelDepartment: 0,
                        parentName: "",
                        phone: "",
                        progress: "",
                        provider: "",
                        providerAgent: "",
                        providerTeacher: "",
                        province: "",
                        qq: "",
                        relationShip: "",
                        school: "",
                        schoolSystem: "",
                        sex: "",
                        signDate: "",
                        signNum: 0,
                        threeLevelDepartment: 0,
                        trackingDate: "",
                        trackingNum: 0,
                        trackingPeople: "",
                        twoLevelDepartment: 0,
                        type: "",
                        updateDate: "",
                        wechat: ""
                    },
                    studentInfoAttr: {
                        comment: "",
                        id: 0,
                        likeBlackboardWriting: "",
                        likeExpression: "",
                        likeLectureStyle: "",
                        likeProfessionAbility: "",
                        parentType: "",
                        signStrategy: "",
                        studentId: 0,
                        weakSubject: ""
                    }
                }
            },
            student_data_from_type_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            //   添加签约信息
            studentSignInfo: {
                belongToAgent: "",
                classNum: "",
                id: this.$route.query.id,
                isReturn: "",
                money: "",
                orderId: "",
                product: "",
                signDate: "",
                signPeople: "",
                studentId: ""
            },
            total: 0,
            currentPage: 1,
            pageSize: 10,
            studentSignInfo2: [],
            //   表单验证
            fieldRules: {
                name: [
                    {
                        required: true,
                        message: "请输入学生姓名",
                        trigger: "blur"
                    }
                ],
                school: [
                    {
                        required: true,
                        message: "请输入学校名称",
                        trigger: "blur"
                    }
                ],
                oemAccount: [
                    { required: true, message: "请输入学籍号", trigger: "blur" }
                ],
                schoolSystem: [
                    {
                        required: true,
                        message: "请输入学生学制",
                        trigger: "blur"
                    }
                ],
                grade: [
                    {
                        required: true,
                        message: "请输入就读年级",
                        trigger: "blur"
                    }
                ],
                account: [
                    {
                        required: true,
                        message: "请输入学生账号",
                        trigger: "blur"
                    }
                ],
                parentName: [
                    {
                        required: true,
                        message: "请输入家长姓名",
                        trigger: "blur"
                    }
                ],
                phone: [
                    {
                        required: true,
                        message: "请输入联系电话",
                        trigger: "blur"
                    }
                ],
                dataFrom: [
                    {
                        required: true,
                        message: "请选择客户来源",
                        trigger: "change"
                    }
                ]
            },
            student_data_from_options: [],
            student_type_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            student_progress_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            student_system_cache_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            grade_cache_gradeOptions: [
                {
                    label: " ",
                    key: " "
                }
            ],
            //   地区
            options: regionData,
            selectedOptions: [],
            student_like_profession_ability: [],
            student_weak_subject: [],
            student_like_expression: [],
            student_like_blackboard_writing: [],
            student_sign_strategy: [],
            student_parent_type: [],
            student_like_lecture_style: [],
            //   多选选中后的数组
            student_parent_type_select: [],
            student_like_blackboard_select: [],
            student_like_expression_select: [],
            student_like_expression_select2: [],
            student_like_lecture_style_select: [],
            student_like_profession_ability_select: [],
            student_weak_subject_select: [],
            student_sign_strategy_select: [],
            selection: false,
            stuTableData: [],
            studentSignReturnChange_select: [], //退单
            student_order_product_options: [],
            student_order_product_options2: [],
            listStudentSignInfo: [], //当前学生签单的订单列表
            sign_date: "", //签约日期
            // 客户跟进数据
            followdata: [],
            columns: [
                { prop: "id", label: "序号", minWidth: 50 },
                { prop: "usernumber", label: "跟进时间", minWidth: 80 },
                { prop: "name", label: "联系人", minWidth: 80 },
                { prop: "OEM", label: "沟通形式", minWidth: 80 },
                { prop: "OEMcategory", label: "客户类型", minWidth: 100 },
                { prop: "role", label: "客户进展", minWidth: 70 },
                {
                    prop: "threeDepartment",
                    label: "下次跟进时间",
                    minWidth: 100
                }
            ],
            pageResult: {},
            pageRequest: { pageNum: 1, pageSize: 8 },
            editLoading: false,
            student_import_department: [],
            roleId: "", //当前登录用户的角色id
            roleId1: "307922416041209975", //咨询师
            roleId2: "307922480151146627", //直销三级部门管理
            roleId3: "307922544034590863", //直销部门管理
            roleId4: "318843899038940998", //金丰和校区管理
            roleId5: "318845886098849661" //金丰和班主任管理
        };
    },
    watch: {
        // $route: "getParams"
    },
    beforeMount: function() {},
    methods: {
        hasPerms: function(perms) {
            // 根据权限标识和外部指示状态进行权限判断
            return hasPermission(perms) & !this.disabled;
        },
        current_change: function(currentPage) {
            this.currentPage = currentPage;
        },
        //   删除订单
        deleteRow(index) {
            this.studentSignInfo2.splice(index, 1);
        },
        // 获取当前页数据
        get_page_data() {
            this.loading3 = true;
            this.$api.student
                .studentQueryInfo({
                    id: this.$route.query.id
                })
                .then(res => {
                    let province = res.studentInfo.province;
                    let city = res.studentInfo.city;
                    let area = res.studentInfo.area;
                    // let provinceCode=TextToCode[province]
                    let reg = new RegExp("(\\d{4})(\\d{2})(\\d{5})");
                    res.studentInfo.phoneStr = res.studentInfo.phone.replace(
                        reg,
                        "$1**$3"
                    );

                    this.loading3 = false;
                    let str = /[\u4e00-\u9fa5]/;
                    if (
                        !str.test(province) &&
                        !str.test(city) &&
                        !str.test(province)
                    ) {
                        this.selectedOptions.push(
                            "" + JSON.parse(res.studentInfo.province) + "",
                            "" + JSON.parse(res.studentInfo.city) + "",
                            "" + JSON.parse(res.studentInfo.area) + ""
                        );
                    }

                    if (res.studentInfoAttr.likeExpression != null) {
                        this.student_like_expression_select2 = res.studentInfoAttr.likeExpression.split(
                            ","
                        );
                    }
                    if (res.studentInfoAttr.likeBlackboardWriting != null) {
                        this.student_like_blackboard_select = res.studentInfoAttr.likeBlackboardWriting.split(
                            ","
                        );
                    }
                    if (res.studentInfoAttr.likeProfessionAbility != null) {
                        this.student_like_profession_ability_select = res.studentInfoAttr.likeProfessionAbility.split(
                            ","
                        );
                    }
                    if (res.studentInfoAttr.weakSubject != null) {
                        this.student_weak_subject_select = res.studentInfoAttr.weakSubject.split(
                            ","
                        );
                    }
                    if (res.studentInfoAttr.likeLectureStyle != null) {
                        this.student_like_lecture_style_select = res.studentInfoAttr.likeLectureStyle.split(
                            ","
                        );
                    }
                    if (res.studentInfoAttr.parentType != null) {
                        this.student_parent_type_select = res.studentInfoAttr.parentType.split(
                            ","
                        );
                    }
                    if (res.studentInfoAttr.signStrategy != null) {
                        this.student_sign_strategy_select = res.studentInfoAttr.signStrategy.split(
                            ","
                        );
                    }
                    this.info.studentInfoDetail.studentInfo = res.studentInfo;
                    console.log(this.info.studentInfoDetail.studentInfo);
                    this.info.studentInfoDetail.studentInfoAttr =
                        res.studentInfoAttr;
                    this.student_data_from_options.forEach(item => {
                        if (
                            item.key ==
                            this.info.studentInfoDetail.studentInfo.dataFrom
                        ) {
                            this.info.studentInfoDetail.studentInfo.dataFrom2 =
                                item.value;
                        }
                    });
                });
        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.currentPage = 1;
            this.fetchData(1, val);
            // console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            this.get_product();
            this.$api.student
                .studentSignList({
                    studentId: this.$route.query.id,
                    pageNum: val
                })
                .then(res => {
                    (this.listStudentSignInfo = res.listStudentSignInfo),
                        this.listStudentSignInfo.forEach(item => {
                            if (item.isReturn == 1) {
                                item.tuidandis = true;
                            } else {
                                item.tuidandis = false;
                            }
                            this.student_order_product_options2.forEach(
                                options2_item => {
                                    if (options2_item.key === item.product) {
                                        item.product2 = options2_item.value;
                                    }
                                }
                            );
                        });
                    this.total = res.total;
                });
        },
        handleFollow(index, row) {
            this.$emit("handleFollow", { index: index, row: row });
            this.dataForm = Object.assign({}, params.row);
            this.$router.push({ path: "/Follow/AddStudentFollow" });
        },
        handleSave() {
            let data = Object.assign({}, this.info);
            let province = this.selectedOptions[0];
            let city = this.selectedOptions[1];
            let area = this.selectedOptions[2];
            this.info.studentInfoDetail.studentInfo.province = province;
            this.info.studentInfoDetail.studentInfo.city = city;
            this.info.studentInfoDetail.studentInfoAttr.likeExpression = this.student_like_expression_select2.toString();
            this.info.studentInfoDetail.studentInfoAttr.likeBlackboardWriting = this.student_like_blackboard_select.toString();
            this.info.studentInfoDetail.studentInfoAttr.weakSubject = this.student_weak_subject_select.toString();
            this.info.studentInfoDetail.studentInfoAttr.likeProfessionAbility = this.student_like_profession_ability_select.toString();
            this.info.studentInfoDetail.studentInfoAttr.likeLectureStyle = this.student_like_lecture_style_select.toString();
            this.info.studentInfoDetail.studentInfoAttr.parentType = this.student_parent_type_select.toString();
            this.info.studentInfoDetail.studentInfoAttr.signStrategy = this.student_sign_strategy_select.toString();
            this.info.studentInfoDetail.studentInfo.area = area;
            this.$refs.studentInfoDetail.validate(valid => {
                if (valid) {
                    this.loading3 = true;
                    this.editLoading = true;
                    this.$api.student.studentInfoUpdate(data).then(res => {
                        if (res.result === 1) {
                            this.$message({
                                message: res.msg,
                                center: true,
                                type: "success"
                            });
                            this.loading3 = false;
                            this.editLoading = false;
                            this.$refs.studentInfoDetail.resetFields();
                            this.closeSelectedTag();
                        } else if (res.result === 2) {
                            this.$message({
                                message: res.msg,
                                center: true,
                                type: "error"
                            });
                            this.loading = false;
                            this.editLoading = false;
                        }
                    });
                } else {
                    this.$message({
                        message: "请填写关键字段",
                        center: true,
                        type: "error"
                    });
                    this.loading = false;
                    this.editLoading = false;
                    return false;
                }
            });
        },
        // 新增订单
        add() {
            this.studentSignInfo2.forEach(element => {
                element.studentId = this.$route.query.id;
            });
            if (this.studentSignInfo2.length == 0) {
                this.studentSignInfo2.push({});
            }
        },
        // 保存签约信息
        addSign() {
            let sindata = {};
            this.studentSignInfo2.forEach((e, item) => {
                (sindata.studentId = this.$route.query.id),
                    (sindata.classNum = e.classNum),
                    (sindata.money = e.money),
                    (sindata.orderId = e.orderId),
                    (sindata.product = e.product),
                    (sindata.signDate = e.signDate);
            });
            this.$api.student.studentSign(sindata).then(res => {
                if (res.result != 1) {
                    this.$message({
                        message: res.msg,
                        type: "error"
                    });
                } else {
                    if (this.studentSignInfo2.length > 0) {
                        this.studentSignInfo2 = [];
                    }
                    this.get_student_sign_list();
                }
            });
        },
        // 获取地区
        handleChange(value) {
            console.log(this.selectedOptions[0]);
        },

        get_profession_ability(params) {
            this.$api.user
                .optionsList({ codeType: "student_like_profession_ability" })
                .then(res => {
                    this.student_like_profession_ability = res.keyValueList;
                });
        },
        get_student_weak_subject() {
            this.$api.user
                .optionsList({ codeType: "student_weak_subject" })
                .then(res => {
                    this.student_weak_subject = res.keyValueList;
                });
        },
        get_student_like_lecture_style() {
            this.$api.user
                .optionsList({ codeType: "student_like_lecture_style" })
                .then(res => {
                    this.student_like_lecture_style = res.keyValueList;
                });
        },
        get_student_like_expression() {
            this.$api.user
                .optionsList({ codeType: "student_like_expression" })
                .then(res => {
                    this.student_like_expression = res.keyValueList;
                });
        },
        get_student_like_blackboard_writing() {
            this.$api.user
                .optionsList({ codeType: "student_like_blackboard_writing" })
                .then(res => {
                    this.student_like_blackboard_writing = res.keyValueList;
                });
        },
        get_student_parent_type() {
            this.$api.user
                .optionsList({ codeType: "student_parent_type" })
                .then(res => {
                    this.student_parent_type = res.keyValueList;
                });
        },
        get_student_sign_strategy() {
            this.$api.user
                .optionsList({ codeType: "student_sign_strategy" })
                .then(res => {
                    this.student_sign_strategy = res.keyValueList;
                });
        },
        get_student_data_from() {
            this.$api.user
                .optionsList({ codeType: "student_data_from" })
                .then(res => {
                    this.student_data_from_options = res.keyValueList;
                });
        },
        get_student_type() {
            this.student_type_options = JSON.parse(
                localStorage.getItem("stdentTpye")
            );
        },
        get_student_progress() {
            this.student_progress_options = JSON.parse(
                localStorage.getItem("studenProgress")
            );
        },
        get_system_cache() {
            this.$api.user
                .optionsList({ codeType: "system_cache" })
                .then(res => {
                    this.student_system_cache_options = res.systemList;
                });
        },
        get_grade_cache() {
            this.$api.user
                .optionsList({ codeType: "grade_cache" })
                .then(res => {
                    this.grade_cache_gradeOptions = res.commonGradeList;
                });
        },
        student_parent_type_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.parentType = value.toString();
        },
        student_like_blackboard_writing_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.likeBlackboardWriting = value.toString();
            console.log(value.toString());
        },
        student_like_expression_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.likeExpression = value.toString();
            console.log(
                this.info.studentInfoDetail.studentInfoAttr.likeExpression
            );
        },
        student_like_lecture_style_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.likeLectureStyle = value.toString();
        },
        student_like_profession_ability_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.likeProfessionAbility = value.toString();
        },
        student_weak_subject_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.weakSubject = value.toString();
        },
        student_sign_strategy_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.signStrategy = value.toString();
        },
        student_data_from_change(value) {
            this.info.studentInfoDetail.studentInfo.dataFrom = value.toString();
        },
        student_progress_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.student_progressValue = value.toString();
        },
        student_system_cache_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.student_system_cacheValue = value.toString();
        },
        student_grade_cache_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.grade_cacheValue = value.toString();
        },
        student_type_change(value) {
            this.info.studentInfoDetail.studentInfo.type = value.toString();
        },
        // 退单
        tuidanChange(index, row) {
            //  console.log(row.isReturn)
            if (row.isReturn == 1) {
                row.tuidandis = true;
            } else {
                row.tuidandis = false;
            }

            this.$api.student
                .studentSignReturn({
                    id: row.id,
                    isReturn: row.isReturn
                })
                .then(res => {
                    this.$message({ message: "退单成功", type: "success" });
                });
        },
        // 获取已经签单的学生的列表
        get_student_sign_list() {
            this.$api.student
                .studentSignList({
                    studentId: this.$route.query.id
                })
                .then(res => {
                    (this.listStudentSignInfo = res.listStudentSignInfo),
                        (this.total = res.total);
                    this.listStudentSignInfo.forEach(item => {
                        this.student_order_product_options2.forEach(
                            options2_item => {
                                if (options2_item.key === item.product) {
                                    item.product2 = options2_item.value;
                                }
                            }
                        );
                        if (item.isReturn == 1) {
                            item.tuidandis = true;
                        } else {
                            item.tuidandis = false;
                        }
                    });
                });
        },
        get_product() {
            // 获取下拉
            this.$api.user
                .optionsList({ codeType: "student_order_product" })
                .then(res => {
                    this.student_order_product_options2 = res.keyValueList;
                });
        },
        isActive(route) {
            return route.path === this.$route.path;
        },
        closeSelectedTag(view) {
            this.$store.dispatch("delVisitedViews", this.$route).then(views => {
                if (this.isActive(this.$route)) {
                    const latestView = views.slice(-1)[0];
                    if (latestView) {
                        this.$router.push(latestView);
                    } else {
                        this.$router.push("/");
                    }
                }
            });
        },
        // 点击客户类型
        typeChange() {
            if (this.info.studentInfoDetail.studentInfo.type == "5") {
                this.info.studentInfoDetail.studentInfo.progress = "8";
            }
        },
        // 点击客户进展
        progressChange() {
            if (this.info.studentInfoDetail.studentInfo.progress == "8") {
                this.info.studentInfoDetail.studentInfo.type = "5";
            }
        },
        // 获取方式
        get_student_data_from_type() {
            this.student_data_from_type_options = JSON.parse(
                localStorage.getItem("stdentDataFromType")
            );
        },
        // 获取导入部门
        get_student_importDepartment() {
            this.$api.user
                .optionsList({ codeType: "student_import_department" })
                .then(res => {
                    this.student_import_department = res.keyValueList;
                });
        },
        // 查询角色信息
        queryUserRole() {
            this.$api.role.queryUserRole().then(res => {
                if (res.result == 1) {
                    this.roleId = res.userInfo.roleId;
                    if (
                        this.roleId == this.roleId1 ||
                        this.roleId == this.roleId2 ||
                        this.roleId == this.roleId3 ||
                        this.roleId == this.roleId4 ||
                        this.roleId == this.roleId5
                    ) {
                        this.customerSource = true;
                        this.customerImportDepartment = true;
                    }
                }
            });
        }
    },
    mounted() {
        this.get_profession_ability();
        this.get_student_weak_subject();
        this.get_student_like_lecture_style();
        this.get_student_like_expression();
        this.get_student_like_blackboard_writing();
        this.get_student_parent_type();
        this.get_student_sign_strategy();
        this.get_student_data_from();
        this.get_student_type();
        this.get_student_progress();
        this.get_system_cache();
        this.get_grade_cache();
        this.get_page_data();
        this.get_student_sign_list();
        this.get_product();
        this.get_student_data_from_type();
        this.get_student_importDepartment();
        this.queryUserRole();
    }
};
</script>
<style lang='scss' scoped>
.el-row .el-col {
    margin-left: 0 !important;
}
.container .el-radio-group .el-radio:first-child {
    display: inline-block !important;
}
.addstu-box .el-cascader {
    width: 100% !important;
}
.demo-form-inline {
    width: 90%;
    margin: 0 auto;
}
.addstu-box {
    text-align: left;
    width: 90%;
    margin: 20px auto;
    border: 1px solid #e4e7ed;
    padding-bottom: 20px;
    .el-row {
        margin: 0 0 2% 0;
    }
    .el-select {
        width: 100%;
    }
    .title h1 {
        font-size: 20px;
        font-weight: bold;
        padding: 20px;
    }
    .city-title {
        text-align: right;
        float: left;
        font-size: 14px;
        color: #606266;
        line-height: 40px;
        padding: 0 12px 0 0;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
    }
}
.el-pagination {
    width: 50%;
    float: right;
    margin-top: 3%;
}
.addstu-box-contain {
    .el-row {
        .el-col i {
            font-style: normal;
            text-align: right;
            float: left;
            font-size: 14px;
            color: #606266;
            line-height: 40px;
            padding: 0 0 0 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
        }
    }
}
.el-checkbox {
    margin-right: 30px;
}
.el-checkbox + .el-checkbox {
    margin-left: 0px;
}
</style>
<style lang="scss">
.editstudent input::-webkit-outer-spin-button,
.editstudent input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
}
.addstu-box {
    .el-cascader {
        width: 100%;
    }
}
.addstu-box {
    .el-cascader {
        width: 100%;
    }
}
.sign-box {
    .el-col:first-child .el-form-item__content {
        width: 60%;
    }
    .el-form-item__content {
        width: 60%;
    }
}
.sign-box {
    .el-table {
        .has-gutter {
            .el-table-column--selection {
                display: none;
            }
        }
    }
}
.editstudent .addstu-box-contain {
    margin: 0 auto;
}
.editstudent .el-form--inline .el-form-item__content {
    width: 100%;
}
.editstudent .el-select {
    width: 100%;
}
.editstudent .el-form--inline .el-form-item {
    margin-bottom: 0 !important;
}
</style>


